/*
 * Created on Jan 16, 2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package com.unash.z3950.pdu;

import java.io.IOException;
import java.util.logging.Logger;

import org.xml.sax.SAXException;

import com.unash.asn.AsnBoolean;
import com.unash.asn.AsnInteger;
import com.unash.asn.AsnObjectIdentifier;
import com.unash.asn.AsnOctetString;
import com.unash.asn.AsnVisibleString;
import com.unash.z3950.query.ExecuteQuery;
import com.unash.z3950.query.RPNProcessor;
/**
 * @author Ashwini Gokhale
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class SearchRequest implements Request {

	private AsnOctetString referenceId;
	private AsnInteger smallSetUpperBound;
	private AsnInteger largeSetLowerBound;
	private AsnInteger MediumSetPresentNumber;
	private AsnBoolean ReplaceIndicator;
	private AsnVisibleString resultSetName;
	private AsnVisibleString[] databaseNames;
	private ElementSetNames smallSetElementSetNames;
	private ElementSetNames mediumSetElementSetNames;
	private AsnObjectIdentifier preferredRecordSyntax;
	private Query query;
	//OtherInformation additionalSearchInfo;
	//OtherInformation otherInfo;
	
	
	/* (non-Javadoc)
	 * @see com.unash.z3950.pdu.Request#process()
	 */
	public Response process() {
		SearchResponse objResponse = new SearchResponse();
		if (query instanceof RPNQuery) {
			try{
				String sql = RPNProcessor.getSql(((RPNQuery)query));
				
				System.out.println("Processing query " + sql);
				
				ExecuteQuery.execute(sql);
							
				objResponse.setResultCount(new AsnInteger(1));
				objResponse.setNumberOfRecordsReturned(new AsnInteger(1));
				objResponse.setNextResultSetPosition(new AsnInteger(0));
				objResponse.setSearchStatus(new AsnBoolean(true));
				objResponse.setPresentStatus(new AsnInteger(0));	
				
			}catch(IOException e){
			}
		    catch(SAXException e){
		    }
		}
		return objResponse;
	}

	/**
	 * @return
	 */
	public AsnVisibleString[] getDatabaseNames() {
		return databaseNames;
	}

	/**
	 * @return
	 */
	public AsnInteger getLargeSetLowerBound() {
		return largeSetLowerBound;
	}

	/**
	 * @return
	 */
	public ElementSetNames getMediumSetElementSetNames() {
		return mediumSetElementSetNames;
	}

	/**
	 * @return
	 */
	public AsnInteger getMediumSetPresentNumber() {
		return MediumSetPresentNumber;
	}

	/**
	 * @return
	 */
	public AsnOctetString getReferenceId() {
		return referenceId;
	}

	/**
	 * @return
	 */
	public AsnBoolean getReplaceIndicator() {
		return ReplaceIndicator;
	}

	/**
	 * @return
	 */
	public AsnVisibleString getResultSetName() {
		return resultSetName;
	}

	/**
	 * @return
	 */
	public ElementSetNames getSmallSetElementSetNames() {
		return smallSetElementSetNames;
	}

	/**
	 * @return
	 */
	public AsnInteger getSmallSetUpperBound() {
		return smallSetUpperBound;
	}

	/**
	 * @param strings
	 */
	void setDatabaseNames(AsnVisibleString[] strings) {
		databaseNames = strings;
	}

	/**
	 * @param integer
	 */
	void setLargeSetLowerBound(AsnInteger integer) {
		largeSetLowerBound = integer;
	}

	/**
	 * @param names
	 */
	void setMediumSetElementSetNames(ElementSetNames names) {
		mediumSetElementSetNames = names;
	}

	/**
	 * @param integer
	 */
	void setMediumSetPresentNumber(AsnInteger integer) {
		MediumSetPresentNumber = integer;
	}

	/**
	 * @param string
	 */
	void setReferenceId(AsnOctetString string) {
		referenceId = string;
	}

	/**
	 * @param boolean1
	 */
	void setReplaceIndicator(AsnBoolean boolean1) {
		ReplaceIndicator = boolean1;
	}

	/**
	 * @param string
	 */
	void setResultSetName(AsnVisibleString string) {
		resultSetName = string;
	}

	/**
	 * @param names
	 */
	void setSmallSetElementSetNames(ElementSetNames names) {
		smallSetElementSetNames = names;
	}

	/**
	 * @param integer
	 */
	void setSmallSetUpperBound(AsnInteger integer) {
		smallSetUpperBound = integer;
	}

	/**
	 * @return
	 */
	public AsnObjectIdentifier getPreferredRecordSyntax() {
		return preferredRecordSyntax;
	}

	/**
	 * @return
	 */
	public Query getQuery() {
		return query;
	}

	/**
	 * @param identifier
	 */
	public void setPreferredRecordSyntax(AsnObjectIdentifier identifier) {
		preferredRecordSyntax = identifier;
	}

	/**
	 * @param query
	 */
	public void setQuery(Query query) {
		this.query = query;
	}

}
